*global  direc  "C:/Users/brunem/Documents/GitHub/STYL_10Y_replication/"
cd $direc

clear all


use          "data/raw/deaths_followup_2022/STYL Deaths Followup.dta"
append using "data/raw/deaths_followup_2022/Pilot STYL Deaths Followup.dta"


**************************************************************
******Use data at this stage to evaluate comments about death
**************************************************************
*x

keep id
bys id: gen count = _n
drop if count > 1
drop count

*Total of updated death accounts is N = 98

** Death description will be coded by hand
gen new_survey_death = "death to be classified"


tempfile updated_deaths
save `updated_deaths'

use "data/clean/STYL_Deaths.dta", clear
merge using `updated_deaths'
drop _merge


** Most people with the new data have 2 surveys, and those tend to agree.
** Odd cases (disagreement, fewer than 1 survey) will be coded by hand.
** Violent deaths and drug related deaths will be coded by hand.

gen n_new_surveys = 2                              if new_survey_death != ""
gen disagreement = 0                               if new_survey_death != ""
gen type_violent_death = "death to be classified"  if new_survey_death != ""
gen drug_indicator     = 0                         if new_survey_death != ""



***********************************************************************
******************* Coding by hands the new data (see line 15)  *******
***********************************************************************
/*
The following lines code by hand the updated death information.
There are a few reasons for this:
i)   We wanted to make the coding of this variable as transparent as possible
ii)  We wanted to make explicit when the 2 death accounts did not match
iii) The descriptions for each death are rather long and they do not necessarily contain key words.

Whenever something was unclear or the accounts were too diferent, we asked the field team to adjudicate based on
the audio recordings of the full interiews as opposed to just the comment the enumerator wrote on the survey.
Those decisions tend to be marked as "As per email".


We categorize every death in
- Violent Death    (Death caused by other people or by the consequences of a fight with someone)
- Illness          (Any health condition not explained by an accident, violent incident or obvious drug overdose )
- Accidental Death
- Other

Furthermore we categorize violent deaths in 2 options:  whether or not they were due to a mob incident as a response to (alleged) stealing.
We also make a note when drugs seem to be acomponent of the death.
*/


replace new_survey_death = "Violent Death" if id == 20007
replace type_violent_death = "due to stealing" if id == 20007


replace new_survey_death = "Illness" if id == 20019



replace new_survey_death = "Illness" if id == 20044


*Not super specific description, I checked w IPA team to decide Illness
replace new_survey_death = "Illness" if id == 20045
replace n_new_surveys = 1 if id == 20045


replace new_survey_death = "Illness" if id == 20058
replace drug_indicator = 1 if id == 20058

replace new_survey_death = "Illness" if id == 20074

*Liver problems
replace new_survey_death = "Illness" if id == 20083
replace n_new_surveys = 1 if id == 20083

replace new_survey_death = "Illness" if id == 20086


replace new_survey_death = "Illness" if id == 20103


replace new_survey_death = "Illness" if id == 20109


*Both accounts say drugs. One says sore (illness?), other says poison.
replace new_survey_death = "Other" if id == 20133
replace disagreement = 1 if id == 20133
replace drug_indicator = 1 if id == 20133

replace new_survey_death = "Illness" if id == 20139


replace new_survey_death = "Violent Death" if id == 20156
replace type_violent_death = "due to stealing" if id == 20156


*One informant is sure is high substance. The other one talks about an unspecific stomach pain.
replace new_survey_death = "Other" if id == 20172
replace disagreement = 1 if id == 20172
replace drug_indicator = 1 if id == 20172


replace new_survey_death = "Illness" if id == 20175

replace new_survey_death = "Illness" if id == 20176


replace new_survey_death = "Violent Death" if id == 20187
replace type_violent_death = "due to stealing" if id == 20187

replace new_survey_death = "Illness" if id == 20208

replace new_survey_death = "Violent Death" if id == 20224
replace type_violent_death = "due to stealing" if id == 20224


*Person dies of pneumonia b/c he sleeps on the street. The respondents claim that drugs was a factor.
replace new_survey_death = "Illness" if id == 20229
replace drug_indicator = 1 if id == 20229

*TB
replace new_survey_death = "Illness" if id == 20238


*Died of complication of 'very big wound on his legs without treatment'. Is wound sign of violence or other type of death?
replace new_survey_death = "Illness (wound)" if id == 20239
*According to email confirmation from field team, there is no info that this would be a violent wound.
replace new_survey_death = "Illness" if id == 20239



replace new_survey_death = "Violent Death/Illness" if id == 20256
replace disagreement = 1 if id == 20256
*According to email confirmation, is definitely Violent Death
replace new_survey_death = "Violent Death" if id == 20256
replace type_violent_death = "cant determine" if id == 20256
*As per email
replace type_violent_death = "not due to stealing" if id == 20256
*However this does not change any result.


replace new_survey_death = "Illness" if id == 20281


*GRAY AREA
replace new_survey_death = "Illness" if id == 20282
*mentions the consumption of drugs but i dont think this counts as a drug complication.


replace new_survey_death = "Violent Death" if id == 20289
replace type_violent_death = "due to stealing" if id == 20289


replace new_survey_death = "Illness" if id == 20299

*Claims of African Sign.
replace new_survey_death = "Illness" if id == 20314


*GRAY AREA
replace new_survey_death = "Other" if id == 20349
replace drug_indicator = 1 if id == 20349

*Check w Albert, super contradictory. but not violent death.
replace new_survey_death = "Illness" if id == 20356
replace disagreement = 1 if id == 20356


replace new_survey_death = "Violent Death" if id == 20362
replace type_violent_death = "backlash" if id == 20362


replace new_survey_death = "Illness" if id == 20364


replace new_survey_death = "Violent Death" if id == 20386
replace type_violent_death = "due to stealing" if id == 20386


replace new_survey_death = "Violent Death" if id == 20399
replace type_violent_death = "due to stealing" if id == 20399


*Swollen feet. What is this ?
replace new_survey_death = "Illness" if id == 30008

replace new_survey_death = "Violent Death" if id == 30013
replace type_violent_death = "due to stealing" if id == 30013


replace new_survey_death = "Violent Death" if id == 30046
replace type_violent_death = "due to stealing" if id == 30046


*Strange Natural death.
replace new_survey_death = "Illness" if id == 30047


replace new_survey_death = "Illness" if id == 30067



*Liver damage due to drugs.
replace new_survey_death = "Illness" if id == 30069
replace drug_indicator = 1 if id == 30069

replace new_survey_death = "Illness" if id == 30099

replace new_survey_death = "Violent Death" if id == 30115
replace type_violent_death = "not due to stealing" if id == 30115


*Swollen feet.
replace new_survey_death = "Illness" if id == 30139
*Swollen feet, again.
replace new_survey_death = "Illness" if id == 30146

replace new_survey_death = "Violent Death" if id == 30170
replace type_violent_death = "not due to stealing" if id == 30170

replace new_survey_death = "Illness" if id == 30171

replace new_survey_death = "Illness" if id == 30208


replace new_survey_death = "Illness" if id == 30214
replace new_survey_death = "Other" if id == 30233


replace new_survey_death = "Illness" if id == 30251


replace new_survey_death = "Illness" if id == 30254


replace new_survey_death = "Illness" if id == 30264



replace new_survey_death = "Violent Death" if id == 30265
replace type_violent_death = "due to stealing" if id == 30265

*Swollen feet.
replace new_survey_death = "Illness" if id == 30268

replace new_survey_death = "Illness" if id == 30269

replace new_survey_death = "Violent Death" if id == 30275
replace type_violent_death = "due to stealing" if id == 30275


replace new_survey_death = "Violent Death" if id == 30280
replace type_violent_death = "due to stealing" if id == 30280



*GRAY AREA
replace new_survey_death = "Illness" if id == 30281
replace drug_indicator = 1 if id == 30281



*Liver cancer ... is this a drug sign ?
replace new_survey_death = "Illness" if id == 30293


replace new_survey_death = "Illness" if id == 30300
replace new_survey_death = "Illness" if id == 30333


replace new_survey_death = "Illness" if id == 30348

replace new_survey_death = "Illness" if id == 30353

*Changed recently, gray area.
replace new_survey_death = "Violent Death" if id == 30356
replace disagreement = 1 if id == 30356
replace type_violent_death = "due to stealing" if id == 30356
replace n_new_surveys = 3 if id == 30356

replace new_survey_death = "Violent Death" if id == 30357
replace type_violent_death = "due to stealing" if id == 30357


replace new_survey_death = "Illness" if id == 30360
replace drug_indicator = 1 if id == 30360


replace new_survey_death = "Violent Death" if id == 30373
replace type_violent_death = "due to stealing" if id == 30373

replace new_survey_death = "Violent Death" if id == 30376
replace type_violent_death = "due to stealing" if id == 30376


replace new_survey_death = "Violent Death" if id == 30391
replace type_violent_death = "due to stealing" if id == 30391


*A doctor said dmg heart due to smoking ... drugs ?
replace new_survey_death = "Illness" if id == 30396


*I asked the field team for more information on this case and ended up adjudacting Accidental Death
replace new_survey_death = "Accidental Death" if id == 30405
replace n_new_surveys = 1 if id == 30405



replace new_survey_death = "Violent Death" if id == 30411
replace type_violent_death = "due to stealing" if id == 30411


replace new_survey_death = "Illness" if id == 30413

replace new_survey_death = "Illness" if id == 30427

replace new_survey_death = "Illness" if id == 30428
replace n_new_surveys = 1 if id == 30428

replace new_survey_death = "Accidental Death" if id == 30433



replace new_survey_death = "Illness" if id == 30442

replace new_survey_death = "Violent Death" if id == 30490
replace type_violent_death = "due to stealing" if id == 30490


*weird death, but I think it is illness... back pain ?
replace new_survey_death = "Illness" if id == 30493
replace n_new_surveys = 1 if id == 30493



replace new_survey_death = "Violent Death" if id == 30497
replace type_violent_death = "due to stealing" if id == 30497


replace new_survey_death = "Illness" if id == 30508

replace new_survey_death = "Illness" if id == 74304088

replace new_survey_death = "Illness" if id == 74555987


replace new_survey_death = "Illness" if id == 74313511

replace new_survey_death = "Other" if id == 74487375
replace n_new_surveys = 1 if id == 74487375




replace new_survey_death = "No comments" if id == 20320
*As per email with field team:
replace new_survey_death = "Accidental Death" if id == 20320
replace n_new_surveys = 1 if id == 20320



replace new_survey_death = "Illness" if id == 30042
replace disagreement = 1 if id == 30042
replace n_new_surveys = 4 if id == 30042
replace drug_indicator = 1 if id == 30042


replace new_survey_death = "Violent Death" if id == 30127
replace type_violent_death = "due to stealing" if id == 30127



replace new_survey_death = "Illness" if id == 30227
replace drug_indicator = 1 if id == 30227
replace disagreement = 1 if id == 30227



replace new_survey_death = "No comments" if id == 30241
replace n_new_surveys = 1 if id == 30241
*As per email:
replace new_survey_death = "Accidental Death" if id == 30241


replace new_survey_death = "Illness" if id == 30290

replace new_survey_death = "Illness" if id == 30322
replace n_new_surveys = 1 if id == 30322



replace new_survey_death = "Illness" if id == 30328


replace new_survey_death = "Accidental Death" if id == 30330

replace new_survey_death = "Illness" if id == 30472
replace n_new_surveys = 1.5 if id == 30472



replace new_survey_death = "No comments" if id == 74176305
*As per email:
replace new_survey_death = "Illness" if id == 74176305


replace new_survey_death = "No comments" if id == 74224393
*As per email:
replace new_survey_death = "Illness" if id == 74224393


replace new_survey_death = "No comments" if id == 74305057
*As per email:
replace new_survey_death = "Violent Death" if id == 74305057
replace type_violent_death = "due to stealing" if id == 74305057




******REPORTED ALIVE cases
*There are claims of the individual being alive.
replace new_survey_death = "reported alive" if id == 20244

*According to Albert, he was surveyed for both rounds.
replace new_survey_death = "reported alive" if id == 74488725

*alive but not surveyed. out of reach ?
replace new_survey_death = "reported alive" if id == 74478203

*in prison.
replace new_survey_death = "reported alive" if id == 30358

**************************************

**********************************************************************************End of hand coding











******************************************************Final Revision

* Coding disagreement is impossible (-1) if there are less than 2 surveys.
* Using a different value than (0) which would indicate agreement
replace disagreement = -1 if n_new_surveys < 2 & n_new_surveys != .


*****If we had a prior reported of death, but we didn't confirm it in this round we would mark as no new information
*****In practice this implies staying with the old information.
replace new_survey_death = "ZNo new information" if death_type != "" & new_survey_death == ""



// browse id death_type new_survey_death n_new_surveys disagreement if disagreement != 0 & new_survey_death != ""
tab  new_survey_death death_type if new_survey_death != ""
// browse id death_type new_survey_death n_new_surveys disagreement if new_survey_death != ""


*********************************************************************









************************************************Coding final death variable

*Take old death type as a base for final variable
cap gen updated_death_type = death_type
replace updated_death_type = death_type


**Replace if there is new death information
replace updated_death_type = new_survey_death if new_survey_death != "" & new_survey_death != "ZNo new information"

**Erase death if reported alive
replace updated_death_type = "" if new_survey_death == "reported alive"


*****Generate binary for violent death due to (allegedly) stealing
gen stealing_violent_death = (type_violent_death == "due to stealing") if !missing(type_violent_death)


****If new account was not obviously related to drugs, mark it as 0 in the indicator.
replace drug_indicator = 0 if drug_indicator != 1 & new_survey_death != "" & new_survey_death != "reported alive"




***Grouping into only 4 categories.
*** This implies that Other now has the the following categories: Poisoning, Suspected Witchcraft and Poison, Unknown, etc.
replace updated_death_type = "Poison suspicion" if inlist(updated_death_type, "Poisoning", "Suspected Witchcraft and Poison", "suspicion of poisoning because of sudden illness/death/stomach pain")
replace updated_death_type = "Other" if inlist(updated_death_type, "Poison suspicion", "Unknown")


**Last check
// browse id death_type new_survey_death updated_death_type
tab  updated_death_type death_type if new_survey_death != ""


**Save Data
keep partid updated_death_type drug_indicator type_violent_death
save "data/clean/STYL_updated_deaths.dta", replace
